<?php
require_once 'config/database.php';

header('Content-Type: application/json');

if (!isset($_GET['brand_id'])) {
    echo json_encode(['error' => 'Brand ID is required']);
    exit;
}

$database = new Database();
$db = $database->getConnection();

$query = "SELECT id, name FROM models WHERE brand_id = ? ORDER BY name";
$stmt = $db->prepare($query);
$stmt->execute([$_GET['brand_id']]);
$models = $stmt->fetchAll(PDO::FETCH_ASSOC);

echo json_encode($models); 